<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:5px;">
    <div style="padding:15px;">学员信息</div>
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>学员姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="name" oninput="kehu()" lay-verify="required" placeholder="学员姓名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>联系方式</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone"  required lay-verify="required|phone|number" placeholder="联系方式" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>来源渠道</label>
                <div class="layui-input-inline">
                    <select name="channel" lay-search="" lay-verify="required" lay-filter="channel">
                        <option value="">请选渠道</option>
                        <option value="-1">转介绍</option>
                        {volist name="data[2]" id="channel"}
                        <option value="{$channel.id}">{$channel['name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">学员性别</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" value="1" class="layui-input" title="男" checked/>
                    <input type="radio" name="sex" value="2" class="layui-input" title="女"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>签单人</label>
                <div class="layui-input-inline">

                    <!--
                    <select name="course_consultant_type">
                        <option value="1" selected>系统</option>
                        <option value="2">公海</option>
                    </select>
                    -->

                    <select name="user_id" lay-search="" lay-verify="required" lay-filter="user_id">
                        <option value="">请选择签单人</option>
                        {volist name="users" id="user"}
                        <option value="{$user.id}">{$user['name']}</option>
                        {/volist}
                    </select>

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">介 绍 人</label>
                <div class="layui-input-inline">
                    <select name="introduction" lay-search="" id="introduction" disabled>
                        <option value="">选择介绍人</option>
                        {volist name="students" id="student"}
                        <option value="{$student.id}">{$student['student_name']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>监护对象</label>
                <div class="layui-input-inline">
                    <select name="guardian" lay-verify="required">
                        <option value=""></option>
                        {foreach name="data[30]" id="vo"}
                        <option value="{$vo.name}">{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>电话号码</label>
                <div class="layui-input-inline">
                    <input type="text" name="guardian_phone" lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="width: 630px;">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <input type="text" name="remark" placeholder="备注信息" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-collapse" style="width: 700px;margin-bottom: 20px;" lay-accordion>
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">查看更多信息</h2>
                <div class="layui-colla-content">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">客户姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" id="student_name" name="student_name" placeholder="客户姓名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">出生日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="birth" id="birth" placeholder="出生日期">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">居住小区</label>
                            <div class="layui-input-inline">
                                <input type="text" name="address"  placeholder="居住小区" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">客户年龄</label>
                            <div class="layui-input-inline">
                                <input type="text" name="age" placeholder="客户年龄" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">就读年级</label>
                            <div class="layui-input-inline">
                                <select name="student_grade" lay-search="">
                                    <option value="">请选年级</option>
                                    {volist name="data[1]" id="grade"}
                                    <option value="{$grade.id}">{$grade['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">学校班级</label>
                            <div class="layui-input-inline">
                                <input type="text" name="school_class" placeholder="学校班级" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">微信账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="weixin" placeholder="请输入微信" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">QQ账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="qq" placeholder="请输入QQ" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>


                    <div class="layui-form-item" hidden>
                        <div class="layui-inline">
                            <label class="layui-form-label">父亲姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="father_name" placeholder="父亲姓名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">父亲电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="father_phone" placeholder="父亲电话" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" hidden>
                        <div class="layui-inline">
                            <label class="layui-form-label">母亲姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="mother_name" placeholder="母亲姓名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">母亲电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="mother_phone" placeholder="母亲电话" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="campus_id" value="{$campus_id}">
                    <input class="layui-btn " lay-submit lay-filter="form" value="保存" readonly>
                </div>
            </div>
        </div>
    </form>
    </div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>
    function kehu() {
        let name = document.getElementById("name").value;
        $('#student_name').val(name);
    }
    layui.use(['element', 'jquery', 'form', 'laydate', 'layer'], function () {
        let $ = layui.$,
            layer = layui.layer,
            element = layui.element,
            form = layui.form,
            laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
            ,trigger: 'click'
        });

        /*来源渠道*/
        form.on('select(channel)', function(data) {
            let channel = data.value;
            console.log(channel);
            if(channel === '-1'){
                $('#introduction').attr('disabled', false);
            }else{
                $('#introduction').attr('disabled', true);
            }
            form.render();
        });

        var type = '{$type}';
        var campus_id = '{$campus_id}';
        var sourse_data = '{$sourse_data}';

        //监听提交
        form.on('submit(form)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            let field = data.field;
            let isLoad;
            $.ajax({
                url: '{:url("Student/add")}',
                method: "post",
                data: field,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 1) {
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.location.href = "{:url('Customer/course_contract')}?student_id=" + result.data + '&campus_id=' +campus_id + '&type=' + type + '&sourse_data=' + sourse_data;
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });
</script>